import request from "@/utils/request";

export interface UserInfo {
  id: number;
  username: string;
  email: string;
  avatar?: string;
  roles: string[];
}

export interface LoginParams {
  username: string;
  password: string;
}

export interface LoginResult {
  token: string;
  userInfo: UserInfo;
}

/**
 * 用户登录
 */
export function login(params: LoginParams) {
  return request.post<LoginResult>("/api/auth/login", params);
}

/**
 * 获取用户信息
 */
export function getUserInfo() {
  return request.get<UserInfo>("/api/auth/userinfo");
}

/**
 * 用户登出
 */
export function logout() {
  return request.post("/api/auth/logout");
}

/**
 * 获取用户列表
 */
export function getUserList(params?: any) {
  return request.get<{ list: UserInfo[]; total: number }>("/api/users", {
    params,
  });
}
